Micron Document
Deavmi's coding shack


Commit fee98748803ceea407d5954cbe0be17cb403a0ee


Parents : 82e9f63
Author : Tristan Brice Velloza Kildaire <deavmi@redxen.eu>
Date : 2026-05-03T18:21:53+02:00

save pipes

Changes

1 files changed, 32 insertions(+), 12 deletions(-)

M monitor.go +32 -12

Diff

diff --git a/monitor.go b/monitor.go
index e52febe..bfbcde4 100644
--- a/monitor.go
+++ b/monitor.go
@@ -24,6 +24,9 @@ type Bruh struct {
// the command
cmd *exec.Cmd
+ // pipes monitored
+ pipes []io.ReadCloser
+
// control signaling
ctx context.Context
cancelFunc context.CancelCauseFunc
@@ -92,12 +95,16 @@ func (b *Bruh) Start() {
if err != nil {
// TODO: Handle this
b.log.Error("Could not obtain standard output pipe for '%s': %v", b.u.Name(), err)
+ } else {
+ b.pipes = append(b.pipes, std_out)
}
std_err, err := e.StderrPipe()
if err != nil {
// TODO: Handle this
b.log.Error("Could not obtain standard error pipe for '%s': %v", b.u.Name(), err)
+ } else {
+ b.pipes = append(b.pipes, std_err)
}
go b.logMonitor(std_out, b.ctx)
@@ -112,24 +119,37 @@ func (b *Bruh) monitor() {
case <-b.ctx.Done():
b.log.Info("Got closing signal: %v", context.Cause(b.ctx))
}
+
+ // TODO: Perform shutdown
}
+const BUFFER_SIZE = 1000
+
// log monitor for the given reader
//
// waits on the
-func (b *Bruh) logMonitor(r io.ReadCloser, ctx context.Context) {
- // TODO: This must spin up some go routine
- // that we can access, when our channel
- // gets Done() we wake up and check for
- // value - assume only reason to wake up
- // is error
- //
- // then we must somehow unblock the reader?
- select {
- case <-ctx.Done():
- b.log.Debug("Log monitor woke up, for a tare down")
- break
+func (b *Bruh) logMonitor(r io.Reader, ctx context.Context) {
+ b.log.Trace("Log monitor for '%s' on fd '%v' enter", b.u.Name(), r)
+ b.log.Trace("Log monitor for '%s' on fd '%v' using buffer size %d", BUFFER_SIZE)
+
+ var buff []byte = make([]byte, BUFFER_SIZE)
+ for {
+ // we read at most `BUFFER_SIZE` bytes per call
+ n, e := r.Read(buff)
+ if e != nil {
+ // TODO: Check context in case maybe something basd happened
+ // like process closed one end of pipe _instead_ of us initiating
+ // a tare down
+ b.log.Debug("Log monitor error returned whilst reading: %v", e)
+ break
+ }
+ buff = buff[0:n] // trim to bytes got
+
+ // TODO: Do something with bytes
+ b.log.Trace("Got %d bytes: '%s'", n, (string)(buff))
}
+
+ b.log.Trace("Log monitor for '%s' on fd '%v' exit", b.u.Name(), r)
}
// signal

Served by rngit 1.5.0 - Generated in 0.11s